package com.keyue.controller;

import com.keyue.common.annotation.AnonymousAccess;
import com.keyue.common.constant.ServerResult;
import com.keyue.domain.vo.admin.AdminMenuQueryVO;
import com.keyue.domain.vo.admin.AdminMenuVO;
import com.keyue.log.Log;
import com.keyue.service.admin.AdminMenuService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @date 2018-12-03
 */
@Api(tags = "系统：菜单管理")
@RestController
@RequestMapping("/keyue/admin/menus")
@SuppressWarnings("unchecked")
public class MenuController {

    @Resource
    private AdminMenuService menuService;

    @ApiOperation("获取前端所需菜单")
    @PostMapping(value = "/build")
    @AnonymousAccess
    public ServerResult buildMenus() {
        return ServerResult.success();
    }

    @ApiOperation("返回全部的菜单")
    @PostMapping(value = "/tree")
    @AnonymousAccess
    public ServerResult getMenuTree() {
        return ServerResult.success();
    }

    @Log("查询菜单")
    @ApiOperation("查询菜单")
    @PostMapping(value = "/all")
    @AnonymousAccess
    public ServerResult all(@RequestBody @Validated AdminMenuQueryVO queryVO) {
        return menuService.all(queryVO);
    }

    @Log("新增菜单")
    @ApiOperation("新增菜单")
    @PostMapping(value = "/add")
    @AnonymousAccess
    public ServerResult add(@RequestBody @Validated AdminMenuVO menuVO) {
        return menuService.add(menuVO);
    }

    @Log("修改菜单")
    @ApiOperation("修改菜单")
    @PostMapping(value = "/edit")
    @AnonymousAccess
    public ServerResult edit(@RequestBody @Validated AdminMenuVO menuVO) {
        return menuService.edit(menuVO);
    }

    @Log("删除菜单")
    @ApiOperation("删除菜单")
    @PostMapping(value = "/delete")
    @AnonymousAccess
    public ServerResult delete(@RequestBody @Validated AdminMenuQueryVO queryVO) {
        return menuService.deleteById(queryVO);
    }
}
